package exercises;


import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * 摩尔斯密码
 */
public class Demo04 {
    public static void main(String[] args) {

        System.out.println(moSi(new String[]{"gin", "zen", "gig", "msg"}));
    }

    public static int moSi( String[] words ) {
        String[] str = {".-","-...","-.-.","-..",".","..-.",
                "--.","....", "..",".---","-.-",".-..","--",
                "-.", "---",".--.","--.-",".-.","...","-",
                "..-","...-",".--","-..-","-.--","--.."};
        Map map = new HashMap();
        int index = 0;
        for (char i = 'a'; i <= 'z'; i++) {
            map.put(i,str[index++]);
        }
        System.out.println(map);
        Set set = new HashSet();
        for (int i = 0; i < words.length; i++) {
            String str1 = "";
            for (int j = 0; j < words[i].length(); j++) {
                str1 += map.get(words[i].charAt(j));
            }
            set.add(str1);
        }
        return set.size();
    }
}
